﻿
@{
    ViewBag.Title = "确认订单";
    Layout = "~/Views/Shared/_UserLayout.cshtml";
}
@section Head{
    <script src="~/common/js/jquery.reveal.js" type="text/javascript"></script>
    <script src="~/common/js/jquery.sumoselect.min.js" type="text/javascript"></script>
    <script src="~/common/js/jquery.jumpto.js" type="text/javascript"></script>
    <link href="~/common/css/Orders.css" rel="stylesheet" type="text/css" />
}
@model OrderInfoModel

<div id="Orders" class="Inside_pages  clearfix">
    <div class="Orders_style clearfix">
        <div class="address clearfix" style="position: relative;">
            <div class="title">收货人信息</div>
            <div class="adderss_list clearfix">
                <div class="title_name">
                    选择收货地址

                    <div style="width: 250px;height: 35px;position: absolute;top: 44px;right: 20px;">

                        @if (Model.Addresses.Count() <= 0)
                        {
                            <a href="~/UserAddress/Index">还没有 收货地址，点击添加 收货地址</a>
                        }
                        else
                        {
                            <a href="~/UserAddress/Index" class="clearfix">点击添加新的 收货地址</a>
                            <select id="address_select" name="addressId" style="width: 250px;height: 35px;background-color: lightgreen;">

                                @foreach (var address in Model.Addresses)
                                {
                                    <option value="@address.Id">@address.PhoneNum--@address.ProvinceName@address.CityName@address.AreaName</option>
                                }

                            </select>
                        }




                    </div>
                    <!-- <a href="#">+添加地址</a> -->
                </div>
                @if (Model.Addresses.Count() > 0)
                {
                    for (int i = 0; i < Model.Addresses.Count(); i++)
                    {
                        if (i == 0)
                        {
                            <div class="Shipping_address" id="@Model.Addresses[i].Id">
                                <ul class="detailed">
                                    <li><label>收货人姓名</label><span>@Model.Addresses[i].ReciverName</span></li>
                                    <li><label>详细地址</label><span>@Model.Addresses[i].ProvinceName@Model.Addresses[i].CityName@Model.Addresses[i].AreaName@Model.Addresses[i].Adress</span></li>
                                    <li><label>邮政编码</label><span>@Model.Addresses[i].PostEmail</span></li>
                                    <li><label>移动电话</label><span>@Model.Addresses[i].PhoneNum</span></li>
                                    <li><label>固定电话</label><span></span></li>
                                    <li><label>电子邮件</label><span></span></li>
                                </ul>
                            </div>
                        }
                        else
                        {
                            <div class="Shipping_address" style="display:none" id="@Model.Addresses[i].Id">
                                <ul class="detailed">
                                    <li><label>收货人姓名</label><span>@Model.Addresses[i].ReciverName</span></li>
                                    <li><label>详细地址</label><span>@Model.Addresses[i].ProvinceName@Model.Addresses[i].CityName@Model.Addresses[i].AreaName@Model.Addresses[i].Adress</span></li>
                                    <li><label>邮政编码</label><span>@Model.Addresses[i].PostEmail</span></li>
                                    <li><label>移动电话</label><span>@Model.Addresses[i].PhoneNum</span></li>
                                    <li><label>固定电话</label><span></span></li>
                                    <li><label>电子邮件</label><span></span></li>
                                </ul>
                            </div>
                        }
                    }
                }
                else
                {
                    <div class="Shipping_address">
                        <ul class="detailed"></ul>
                    </div>
                }

            </div>
            @*<!--<div class="list" id="select">
                            <ul class="confirm active">
                            <div class="default">默认地址</div>
                            <div class="adderss_operating">
                             <div class="Operate"><a href="#" class="delete_btn"></a> <a href="#" class="modify_btn"></a></div>
                            </div>
                            <div class="user_address">
                            <li>小张</li>
                            <li>四川成都高新区创业路10号3栋1单元1102式</li>
                            <li class="Postcode">610043</li>
                            <li>18908269130</li>
                            </div>
                            </ul>
                             <ul class="">
                              <div class="adderss_operating">
                             <div class="Operate"><a href="#" class="delete_btn"></a> <a href="#" class="modify_btn"></a></div>
                            </div>
                             <div class="user_address">
                            <li>小张</li>
                            <li>四川成都高新区创业路10号3栋1单元1102式</li>
                            <li class="Postcode">610043</li>
                            <li>18908269130</li>
                            </div>
                            </ul>
                             <ul class="">
                              <div class="adderss_operating">
                             <div class="Operate"><a href="#" class="delete_btn"></a> <a href="#" class="modify_btn"></a></div>
                            </div>
                             <div class="user_address">
                            <li>小张</li>
                            <li>四川成都高新区创业路10号3栋1单元1102式</li>
                            <li class="Postcode">610043</li>
                            <li>18908269130</li>
                            </div>
                            </ul>
                            </div>
                           </div>
                -->*@
            <!--收货地址样式-->


            <form class="form" method="post">
                <fieldset>
                    <!--快递选择-->
                    <div class="express_delivery">
                        <div class="title_name">选择快递方式</div>
                        <input type="hidden" name="orderId" value="@Model.Order.Id" />
                        <input type="hidden" name="addressId" id="addressId" value="@(Model.Addresses.Count() > 0 ? Model.Addresses[0].Id : 0)" />
                        <ul class="dowebok">
                            @{ int count = 0; }
                            @foreach (var express in Model.Express)
                            {
                                <li>
                                    <input value="@express.Id" type="radio" checked="@(count++ == 0)" name="expressId" data-labelauty="@express.Name">
                                    <div class="description">
                                        <em class="arrow"></em>
                                        <p>资费：15元</p>
                                        <p>此价格供参考，详情请咨询@(express.Name)当地营业网点</p>
                                        <p class="Note">满68元包邮</p>
                                        <p><a href="javascript:void(0)">点击查看是否在配送范围内</a></p>
                                    </div>
                                </li>
                            }
                        </ul>

                    </div>

                    <!--付款方式-->
                    <div class="payment">
                        <div class="title_name">支付方式</div>
                        <ul>
                            @{count = 0; }
                            @foreach (var payWay in Model.PayWays)
                            {
                                <li><input value="@payWay.Id" checked="@(count++ == 0)" type="radio" name="payWayId" data-labelauty="@payWay.Name"></li>
                            }
                        </ul>
                    </div>
                    <!--发票样式-->
                    <div class="invoice_style">
                        <ul>
                            <li class="invoice_left"><input name="" type="checkbox" value="" disabled="disabled" data-labelauty="选择发票类型" /> </li>
                            <li class="invoice_left">
                                <select name="receiptId" class="SlectBox">
                                    @foreach (var receipt in Model.Receipts)
                                    {
                                        <option value="@receipt.Id">@receipt.Name</option>
                                    }
                                </select>
                            </li>
                        </ul>
                    </div>
                    <!--产品列表-->
                    <div class="Product_List">
                        @*<div class="envelopes">
                                选择已有红包<select name="somename" class="SlectBox" onclick="console.log($(this).val())" onchange="console.log('change is firing')">
                                    <option disabled="disabled" selected="selected">选择红包金额</option>
                                    <!--placeholder-->
                                    <option value="5元红包">5元红包</option>
                                    <option value="10元红包">10元红包</option>
                                    <option value="20元红包">20元红包</option>
                                    <option value="50元红包">50元红包</option>
                                    <option value="100元红包">100元红包</option>
                                    <option value="200元红包">200元红包</option>
                                </select>
                                或者输入红包序列号<input name="" type="text" class="text_number" /><input type="submit" class="verification_btn" value="验证序列号" />
                            </div>*@

                        <table>
                            <thead><tr class="title"><td class="name">商品名称</td><td class="price">商品价格</td><td class="Preferential">包装价格</td><td class="Quantity">购买数量</td><td class="Money">金额</td></tr></thead>
                            <tbody>

                                @{
                                    float goodPric = 0;

                                }

                                @foreach (var orderRecord in Model.OrderRecordModels)
                                {
                                    <tr>
                                        <td class="Product_info">
                                            <a target="_blank" href="/Home/Detail?goodid=@orderRecord.OrderRecord.GoodId"><img src=@("http://static.amortal.top/" + orderRecord.ImgSrc + "?imageView2/2/w/200/h/200/interlace/1/q/100") width="100px" height="100px" /></a>
                                            <a target="_blank" href="/Home/Detail?goodid=@orderRecord.OrderRecord.GoodId" class="product_name">@orderRecord.OrderRecord.GoodName - @orderRecord.OrderRecord.PackName</a>
                                        </td>
                                        <td><i>￥</i>@orderRecord.OrderRecord.GoodPrice</td>
                                        <td><i>￥</i>@orderRecord.OrderRecord.PackPric</td>
                                        <td>@orderRecord.OrderRecord.Count</td>
                                        <td class="Moneys"><i>￥</i>@orderRecord.OrderRecord.Price</td>
                                    </tr>

                                    goodPric += orderRecord.OrderRecord.Price;
                                }
                            </tbody>
                        </table>
                        <div class="Pay_info">
                            <label>订单留言</label><input name="" type="text" onkeyup="checkLength(this);" class="text_name " />  <span class="wordage">剩余字数：<span id="sy" style="color:Red;">50</span></span>
                        </div>
                        <!--价格-->
                        <div class="price_style">
                            <div class="right_direction">
                                <ul>
                                    <li><label>商品总价</label><i>￥</i><span>@goodPric</span></li>
                                    <li><label>配&nbsp;&nbsp;送&nbsp;&nbsp;费</label><i>￥</i><span>@(Model.Order.Amount >= 68 ? 0 : 15)</span></li>
                                    <li class="shiji_price"><label>实&nbsp;&nbsp;付&nbsp;&nbsp;款</label><i>￥</i><span>@(Model.Order.Amount = goodPric + (Model.Order.Amount >= 68 ? 0 : 15))</span></li>
                                </ul>
                                <div class="btn"><input type="button" lay-submit="" lay-filter="add" value="提交订单" class="submit_btn" /> <input name="" type="button" value="返回购物车" class="return_btn" /></div>
                                @*<div class="integral right">待订单确认后，你将获得<span>345</span>积分</div>*@
                            </div>
                        </div>

                    </div>
                </fieldset>
            </form>
        </div>
    </div>
    <!--友情链接-->
    <div class="Links">
        <div class="link_title">友情链接</div>
        <div class="link_address"><a href="#">四川茶叶协会</a>  <a href="#">链接地址</a>  <a href="#">链接地址</a>  <a href="#">链接地址 </a>   <a href="#">链接地址</a> <a href="#">链接地址</a> <a href="#">链接地址</a></div>
    </div>
</div>
@section FooterScript{
    <script src="~/common/Threelinkage/layui/layui.all.js"></script>
    <script type="text/javascript">

        layui.config({
            base: "js/"
        }).use(['form', 'layer', 'jquery', 'layedit'], function () {
            var form = layui.form,
                layer = parent.layer === undefined ? layui.layer : parent.layer,
                laypage = layui.laypage,
                layedit = layui.layedit,
                $ = layui.jquery;


            form.on('select(ProvinceId)', function (data) {
                index = layer.msg('区域加载中，请稍候', { icon: 16, time: false, shade: 0.8 });
                //获取市
                province = data.value;
                city = null;

                $(".AddressId").html("");
                getCity(province, function () {

                    //获取区
                    area = null;
                    getArea(city);
                });

            });

            form.on('select(CityId)', function (data) {

                city = data.value;
                area = null;
                getArea(city);


            });



            //数据验证
            form.verify({
                username: function (value, item) { //value：表单的值、item：表单的DOM对象
                    if (!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)) {
                        return '用户名不能有特殊字符';
                    }
                    if (/(^\_)|(\__)|(\_+$)/.test(value)) {
                        return '用户名首尾不能出现下划线\'_\'';
                    }
                    if (/^\d+\d+\d$/.test(value)) {
                        return '用户名不能全为数字';
                    }
                },
                ReciverAddress: [/^[\u4E00-\u9FA5A-Za-z0-9_]{0,200}$/, "留言中不能出现特殊字符并且不能多余200个字"],
                PostEmail: [/[1-9]\d{5}(?!\d)/, "请输入正确的邮政编码"],
                //我们既支持上述函数式的方式，也支持下述数组的形式
                //数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]
                pass: [
                    /^[\S]{6,12}$/
                    , '密码必须6到12位，且不能出现空格'
                ]
            });


            //此处的addNew是38行代码中提交按钮的 lay-filter属性
            form.on("submit(add)", function (data) {

                var index = layer.msg('正在支付，请稍候', { icon: 16, time: false, shade: 0.8 });

                var formData = $(".form").serialize();    //表单数据

                $.ajax({
                    url: "/Order/SubmitOrder",
                    type: "post",
                    dataType: "json",
                    data: formData,
                    traditional: true,//这里设置为true
                    success: function (res) {
                        if (res.status == "ok") {
                            layer.close(index);
                            layer.msg("支付成功", {
                                icon: 1, time: 2000, end: function () {

                                    location.href = "/User/UserOrder";
                                }
                            });



                        } else {
                            layer.close(index);
                            layer.msg("支付失败:" + res.errorMsg, {
                                icon: 5, time: 2000, end: function () {

                                    layer.closeAll("iframe");
                                    location.reload();
                                }
                            });
                        }
                    },
                    error: function () {
                        top.layer.close(index);
                        layer.msg("网络请求失败,请刷新页面后重试", {
                            icon: 5, time: 2000, end: function () {

                                layer.closeAll("iframe");

                            }
                        });
                    }
                });

                return false;
            })

        })

    </script>
    <script type="text/javascript">
        function checkLength(which) {
            var maxChars = 50; //
            if (which.value.length > maxChars) {
                alert("您出入的字数超多限制!");
                // 超过限制的字数了就将 文本框中的内容按规定的字数 截取
                which.value = which.value.substring(0, maxChars);
                return false;
            } else {
                var curr = maxChars - which.value.length; //250 减去 当前输入的
                document.getElementById("sy").innerHTML = curr.toString();
                return true;
            }
        }
    </script>
    <script>
        $(function () {
            $(':input').labelauty();

            $('#address_select').change(function () {
                $(".Shipping_address").hide();
                $(".Shipping_address[id='" + $(this).val() + "']").show();
                $("#addressId").val($(this).val());
            });
        });
    </script>
}